<template>
  <div>
    <div id="userList" class="same-change-oldstyle">
      <div class="same-head-box">
        <div class="saem-seat-box">
          <div class="saem-seat-left">
            <span>当前位置：</span>
            <el-breadcrumb separator-class="el-icon-arrow-right">
              <el-breadcrumb-item>用户管理</el-breadcrumb-item>
              <el-breadcrumb-item :to="{ path: '/userlist' }">我的用户</el-breadcrumb-item>
              <el-breadcrumb-item>编辑用户</el-breadcrumb-item>
            </el-breadcrumb>
          </div>
          <div class="saem-seat-right">
            <div class="saem-seat-right">
              <button class="same-search-btns same-search-export" @click="RefreshFun">
                刷新
              </button>
              <button class="same-search-btns" @click="returnBack">返回</button>
            </div>
            <!-- <button class="same-search-btns" @click="returnBack">返回</button> -->
          </div>
        </div>
      </div>
      <div class="u-box">
        <div class="u-box-titile"><i class="el-icon-user"></i> 用户信息</div>
        <div class="u-box-wrapper">
          <el-form label-width="80px">
            <el-form-item label="用户">
              <el-input size="medium" clearable v-model="name" placeholder="请填写用户姓名"></el-input>
            </el-form-item>

            <el-form-item label="手机号码">
              <el-input type="tel" maxlength="11" clearable size="medium" v-model="phone" placeholder="请填写手机号码">
              </el-input>
            </el-form-item>

            <el-form-item label="身份证号">
              <el-input maxlength="18" size="medium" clearable v-model="idcard" placeholder="请填写身份证号"></el-input>
            </el-form-item>

            <el-form-item>
              <el-button size="medium" class="submit-class" type="primary" @click="edit">提 交</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
  export default {
    name: "cardEdit",
    data() {
      return {
        name: "",
        phone: "",
        idcard: "",
      };
    },
    inject: ["reload"],
    mounted() {
      this.getUser();
    },
    created() {
      this.user_id = this.$route.query.user_id;
    },
    methods: {
      edit() {
        this.$post({
          url: "Partner/Users/editUserinfo",
          data: {
            name: this.name,
            phone: this.phone,
            IDcard: this.idcard,
            user_id: this.user_id
          },
          success: (res) => {
            if (res.code > 0) {
              this.$message({
                type: "success",
                message: res.message,
              });
              setTimeout(() => {
                this.$router.back(-1);
              }, 1500)
            } else {
              this.$message({
                message: res.message,
                type: "error",
              });
            }
          },
        });
      },

      getUser() {
        this.$post({
          url: "Partner/Users/getUserinfo",
          data: {
            user_id: this.user_id,
            type: 1,
          },
          success: (res) => {
            if (res.code > 0) {
              const data = res.data;
              this.name = data.name;
              this.phone = data.phone;
              this.idcard = data.IDcard;
            } else {
              this.$message({
                message: res.message,
                type: "error",
              });
            }
          },
          error: (err) => { },
        });
      },

      onSubmit() {
        console.log("submit!");
      },

      RefreshFun() {
        // 调用reload方法，刷新整个页面
        this.reload();
      },
      //返回
      returnBack() {
        this.$router.back(-1);
      },
    },
  };
</script>
<style scoped>
  .same-head-box {
    border-bottom: none;
  }

  .u-box {
    padding: 20px 40px 0;
  }

  .u-box-titile {
    color: #2d5686;
    font-weight: bolder;
  }

  .u-box-wrapper {
    padding-top: 20px;
    width: 400px;
  }

  .el-form-item {
    margin-bottom: 15px !important;
  }
</style>